{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1、一些彩蛋"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Zen of Python, by Tim Peters\n",
      "\n",
      "Beautiful is better than ugly.\n",
      "Explicit is better than implicit.\n",
      "Simple is better than complex.\n",
      "Complex is better than complicated.\n",
      "Flat is better than nested.\n",
      "Sparse is better than dense.\n",
      "Readability counts.\n",
      "Special cases aren't special enough to break the rules.\n",
      "Although practicality beats purity.\n",
      "Errors should never pass silently.\n",
      "Unless explicitly silenced.\n",
      "In the face of ambiguity, refuse the temptation to guess.\n",
      "There should be one-- and preferably only one --obvious way to do it.\n",
      "Although that way may not be obvious at first unless you're Dutch.\n",
      "Now is better than never.\n",
      "Although never is often better than *right* now.\n",
      "If the implementation is hard to explain, it's a bad idea.\n",
      "If the implementation is easy to explain, it may be a good idea.\n",
      "Namespaces are one honking great idea -- let's do more of those!\n"
     ]
    }
   ],
   "source": [
    "import this\n",
    "# 经典 Python 之禅"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 优美胜于丑陋。\n",
    "* 显式胜于隐式。\n",
    "* 简单胜于复杂。\n",
    "* 复杂胜于难懂。\n",
    "* 扁平胜于嵌套。\n",
    "* 稀疏胜于紧密。\n",
    "* 可读性应当被重视。\n",
    "* 尽管实用性会打败纯粹性，特例也不能凌驾于规则之上。\n",
    "* 不要忽略任何错误，除非你确认要这么做\n",
    "* 面对不明确的定义，拒绝猜测的诱惑。\n",
    "* 找到一种最好唯一的一种方法去解决问题。\n",
    "* 虽然一开始这种方法并不是显而易见，因为你不是 Python 之父。\n",
    "* 做好过不做，但没有思考的做还不如不做\n",
    "* 如果实现很难说明，那它是个坏想法。\n",
    "* 如果实现容易解释，那它有可能是个好想法。\n",
    "* 命名空间是个绝妙的想法，请多加利用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import antigravity\n",
    "# 弹出漫画"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、两种主要代码运行模式：脚本模式、交互式模式\n",
    "* 当我们编写Python代码时，我们得到的是一个包含Python代码的以.py为扩展名的文本文件。要运行代码，就需要Python解释器去执行.py文件\n",
    "* 脚本模式：启动python解释器直接运行脚本代码.py文件\n",
    "* 交互式模式：用“>>>”符号表示，输入python代码后立刻执行\n",
    "* 注意了：jupyter notebook导出的ipynb文件，和.py文件区分开"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "# 脚本模式\n",
    "# sublime演示\n",
    "print('hello world!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hello world'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 交互式模式\n",
    "# cmd中演示\n",
    "'hello world'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3、用#书写笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n"
     ]
    }
   ],
   "source": [
    "a = 3\n",
    "b = 4\n",
    "print(a*b)\n",
    "# 计算a乘以b\n",
    "# 看到了吗，单行注释就用#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n也可以用三个双引号\\n也可以用三个双引号\\n也可以用三个双引号\\n'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "这是多行注释，用三个单引号\n",
    "这是多行注释，用三个单引号 \n",
    "这是多行注释，用三个单引号\n",
    "'''\n",
    "\"\"\"\n",
    "也可以用三个双引号\n",
    "也可以用三个双引号\n",
    "也可以用三个双引号\n",
    "\"\"\"\n",
    "# 多行注释"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4、什么是变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "245\n",
      "2.24\n",
      "这是一个字符串\n"
     ]
    }
   ],
   "source": [
    "# 首先，什么是“客观存在的值”\n",
    "print(245)\n",
    "print(2.24)\n",
    "print('这是一个字符串')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 4.2 abc [1, 2, 3, 4]\n",
      "<class 'int'> <class 'float'> <class 'str'> <class 'list'>\n",
      "1608253936 2439863787048 2439818609640 2439880357832\n"
     ]
    }
   ],
   "source": [
    "# 那么变量又是什么呢？ → 变：变化，重在变字，量：计量，衡量，表示一种状态\n",
    "# 赋值运算 → =\n",
    "a = 1\n",
    "b = 4.2\n",
    "c = 'abc'\n",
    "d = [1,2,3,4]\n",
    "print(a,b,c,d)\n",
    "print(type(a),type(b),type(c),type(d))\n",
    "print(id(a),id(b),id(c),id(d))\n",
    "# 当变量被定义（指向一个特定存在的值）则存在\n",
    "# 这里定义了4个变量，且其数据类型分别为：数值-整型、数值-浮点型、字符串、列表\n",
    "# 用 = 来给变量赋值 → =左边是一个变量名,=右边是存储在变量中的值\n",
    "# id() 函数用于获取对象的内存地址\n",
    "# type()查看数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "hello world <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 再来看看为什么说python是一个“动态数据类型”的语言\n",
    "a = 1\n",
    "print(a,type(a))\n",
    "a = 'hello world'\n",
    "print(a,type(a))\n",
    "# 变量定义时不需要声明数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 1\n",
      "1608253936 1608253936 1608253936\n",
      "1 2 3\n",
      "1608253936 1608253968 1608254000\n"
     ]
    }
   ],
   "source": [
    "# 多变量赋值\n",
    "a = b = c = 1\n",
    "print(a,b,c)\n",
    "print(id(a),id(b),id(c))\n",
    "a,b,c = 1,2,3\n",
    "print(a,b,c)\n",
    "print(id(a),id(b),id(c))\n",
    "# 这里注意了，id可以查看到其指定值得对象内存地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1608253936 2439863787048\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 注意值的指向\n",
    "a = 1\n",
    "b = 1.0\n",
    "print(id(a),id(b))\n",
    "print(a is b)\n",
    "print(a == b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除变量\n",
    "del a\n",
    "#print(a)\n",
    "# 删除变量后，会报错"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "变量定义需要注意的地方 → 变量名的问题\n",
    "* 一般用英文字母作为开头，变量名中不能含有空格，不能以数字、空格开头，同时建议不要用中文\n",
    "* 不能用函数名作为变量名 → 这里演示一下"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5、模块导入\n",
    "* import ...\n",
    "* import ... as ...\n",
    "* from import ...\n",
    "* 关于模块的安装 → pip install..."
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
